/*
 * Copyright (c)  2017
 * All rights reserved.
 * OrderItemEntity.java 2017-09-17 下午3:42
 */

package com.ueboot.weishop.entity.order;

import com.ueboot.weishop.entity.IDEntity;
import com.ueboot.weishop.entity.goods.GoodsInfoEntity;
import com.ueboot.weishop.entity.setting.CategoryEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;

/**
 * 描述:订单子项。用于一个订单购买多件商品时使用。
 *
 * @author yangkui create on 2017-09-17 下午3:42.
 * @since 1.0
 */
@Data
@NoArgsConstructor
@Entity(name = "WS_ORDER_ITEM")
public class OrderItemEntity extends IDEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "WS_ORDER_ITEM")
    @GenericGenerator(name = "WS_ORDER_ITEM", strategy = "enhanced-table", parameters = {
            @org.hibernate.annotations.Parameter(name = "table_name", value = "WS_TABLE_SEQUENCE"),
            @org.hibernate.annotations.Parameter(name = "segment_value", value = "WS_ORDER_ITEM"),
            @org.hibernate.annotations.Parameter(name = "optimizer", value = "pooled") })
    @Column(name = "ID",columnDefinition = "INT(20) COMMENT 'id主键'",length = 20)
    private Long id;

    /**
     * 商品主图地址(冗余）
     */
    @Column(name = "MAIN_IMG_URL",columnDefinition = "VARCHAR(200) COMMENT '商品主图地址'",length = 200)
    private String mainImgUrl;
    /**
     * 商品名称（冗余）
     */
    @Column(name = "GOODS_NAME",columnDefinition = "VARCHAR(200) COMMENT '商品名称（冗余）'",length = 200)
    private String goodsName;

    /**
     * 订单中的商品数量
     */
    @Column(name = "GOODS_COUNT",columnDefinition = "INT(11) COMMENT '订单中的商品数量'",length = 11)
    private int goodsCount;

    /**
     * 商品数量单位：如，个、件
     */
    @Column(name = "UNIT",columnDefinition = "VARCHAR(40) COMMENT '商品数量单位：如，个、件'",length = 40)
    private String unit;

    /**
     * 所属分类
     */
    @ManyToOne
    @JoinColumn(name="CATEGORY_ID",columnDefinition = "INT(20) COMMENT '所属分类'")
    private CategoryEntity category;


    /**
     * 商品原始价格
     * 分为单位
     */
    @Column(name = "ORIGINAL_PRICE",columnDefinition = "INT(11) COMMENT '订单原始价格'",length = 11)
    private int originalPrice;

    /**
     * 所属订单
     */
    @ManyToOne
    @JoinColumn(name="ORDER_ID",columnDefinition = "INT(20) COMMENT '所属订单'")
    private OrderEntity order;

    /**
     * 商品信息（关联商品，无法确保为当时购买是的商品信息）
     */
    @ManyToOne
    @JoinColumn(name="GOODS_INFO_ID",columnDefinition = "INT(20) COMMENT '商品信息'")
    private GoodsInfoEntity goodsInfo;



}